# -*- coding: utf-8 -*-
from django import forms
from django.contrib.auth import authenticate


class LoginForm(forms.Form):
    username = forms.CharField(max_length=64)
    password = forms.CharField(max_length=64)

    def clean_password(self):
        user = authenticate(
            username = self.cleaned_data.get("username"),
            password = self.cleaned_data.get("password")
        )
        if not user:
            raise forms.ValidationError("Не правильный логин или пароль")

        if not user.is_active:
            raise forms.ValidationError("Данный аккаунт был заблокирован")

        self.user = user
        return self.cleaned_data.get("password")